﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration.Health;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;

namespace SDS.SPHealthAnalyzerRules.Delegation.Tests.Rules
{
    [TestClass]
    public class WebApplications : Base
    {
        [TestMethod]
        public void WebAppAppPools_Using_DomainAccount()
        {
            var analyzerRule = new SDS.SPHealthAnalyzerRules.Delegation.Rules.WebAppAppPools_Using_DomainAccount();
            var Results = analyzerRule.Check();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(analyzerRule));
        }

        [TestMethod]
        public void WebAppHostHeaders_Have_SPNs()
        {
            var analyzerRule = new SDS.SPHealthAnalyzerRules.Delegation.Rules.WebAppHostHeaders_Have_SPNs();

            var Results = analyzerRule.Check();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(analyzerRule));
        }

        [TestMethod]
        public void WebAppAppPools_Using_Delegation()
        {
            var analyzerRule = new SDS.SPHealthAnalyzerRules.Delegation.Rules.WebAppAppPools_Using_Delegation();

            var Results = analyzerRule.Check();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(analyzerRule));
        }

        #region Kerberos authentication provider rules

        [TestMethod]
        public void WebApplications_Using_Delegation__Not_Using_ANY_Kerberos_AuthenticationProvider()
        {
            // one of the kerb auth providers must exist
            var rule = new Delegation.Rules.WebApps__Using_Kerberos_AuthProvider();

            var Results = rule.Check();

            rule.AutomaticExecutionParameters.Scope.Should().Be(SPHealthCheckScope.All);
            rule.AutomaticExecutionParameters.ServiceType.Should().Be<Microsoft.SharePoint.Administration.SPWebService>();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(rule));
        }

        [TestMethod]
        public void WebApplications_Using_Delegation__Not_Using_NTLM_AuthenticationProvider()
        {
            // one of the kerb auth providers must exist
            var rule = new Delegation.Rules.WebApps__Using_NTLM_AuthProvider();

            var Results = rule.Check();

            rule.AutomaticExecutionParameters.Scope.Should().Be(SPHealthCheckScope.All);
            rule.AutomaticExecutionParameters.ServiceType.Should().Be<Microsoft.SharePoint.Administration.SPWebService>();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(rule));
        }

        [TestMethod]
        public void WebApplications_Using_Delegation__Kerb_Is_Preferred_AuthenticationProvider()
        {
            // one of the kerb auth providers should be the preference
            var rule = new Delegation.Rules.WebApps__Kerb_Is_Preferred_AuthProvider();

            var Results = rule.Check();

            rule.AutomaticExecutionParameters.Scope.Should().Be(Microsoft.SharePoint.Administration.Health.SPHealthCheckScope.All);
            rule.AutomaticExecutionParameters.ServiceType.Should().Be<Microsoft.SharePoint.Administration.SPWebService>();

            Results.Should().Be(SPHealthCheckStatus.Passed, TestHealthRule_Message(rule));
        }

        #endregion

    } // class
} // namespace
